//
//  ByDocumentarySectionView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/27.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentarySectionView.h"

@implementation ByDocumentarySectionView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        UILabel *line = [[UILabel alloc] init];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(4, 17));
        }];
        line.backgroundColor = BY_THEME_COLOR;
        
        UIButton *hotBtn = [[UIButton alloc] init];
        [self addSubview:hotBtn];
        [hotBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(24);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(80, 20));
        }];
        hotBtn.titleLabel.font =B_FONT(17);
        [hotBtn setTitle:@"热门跟单" forState:UIControlStateNormal];
        [hotBtn setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
        hotBtn.tag = 100;
        
        UIButton *focusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:focusBtn];
        [focusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(70, 20));
        }];
        focusBtn.titleLabel.font = FONT(15);
        [focusBtn setTitle:@"我的关注" forState:UIControlStateNormal];
        [focusBtn setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
        focusBtn.tag = 101;
        [focusBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(focusBtn.mas_left).offset(-5);
            make.centerY.equalTo(focusBtn.mas_centerY).offset(0);
            make.size.mas_equalTo(CGSizeMake(15, 12));
        }];
        imageView.image = [UIImage imageNamed:@"qiehuan切换"];
        
    }
    return self;
}

- (void)searchAction:(UIButton *)btn{
    if (self.searchBlock) {
        self.searchBlock();
    }
}

- (void)setIndex:(NSInteger)index{
    _index = index;
    UIButton *btn1 = [self viewWithTag:100];
    UIButton *btn2 = [self viewWithTag:101];
    if (self.index == 0) {
        [btn2 setTitle:@"我的关注" forState:UIControlStateNormal];
        [btn1 setTitle:@"热门跟单" forState:UIControlStateNormal];
    }else{
        [btn2 setTitle:@"热门跟单" forState:UIControlStateNormal];
        [btn1 setTitle:@"我的关注" forState:UIControlStateNormal];
    }
}

- (void)btnAction:(UIButton *)btn{
    UIButton *btn1 = [self viewWithTag:100];
    UIButton *btn2 = [self viewWithTag:101];
    if ([btn2.titleLabel.text isEqualToString:@"我的关注"]) {
        [btn2 setTitle:@"热门跟单" forState:UIControlStateNormal];
        [btn1 setTitle:@"我的关注" forState:UIControlStateNormal];
        if (self.selectBlock) {
            self.selectBlock(1);
        }
    }else if ([btn2.titleLabel.text isEqualToString:@"热门跟单"]){
        [btn2 setTitle:@"我的关注" forState:UIControlStateNormal];
        [btn1 setTitle:@"热门跟单" forState:UIControlStateNormal];
        if (self.selectBlock) {
            self.selectBlock(0);
        }
    }
    
   
}
@end
